use "C:\Users\Baris\Dropbox\Fragmentation\IP_paper_submission\analysis\replication_files\HKS.dta", clear
set more off

tsset dyad_id time

// CONTROLS
global CONTROLS ceasefire rebstrength numofrebgroups lntpop biased_intervention brv_AllLag

// Main model: cfi_lag
nbreg brv_All cfi_lag troopLag1000 policeLag1000 milobsLag1000 $CONTROLS if active_year==1 | peacedurplus24!=., cl(dyad_id)
gen sample = 1 if e(sample) == 1

// Model 6 original
nbreg brv_All troopLag1000 policeLag1000 milobsLag1000 ceasefire rebstrength numofrebgroups lntpop biased_intervention brv_AllLag if active_year==1 | peacedurplus24!=., cl(dyad_id)

// Model 7 original reduced sample
nbreg brv_All troopLag1000 policeLag1000 milobsLag1000 $CONTROLS if sample == 1, cl(dyad_id)

// Model 8: cfi_lag
nbreg brv_All cfi_lag troopLag1000 policeLag1000 milobsLag1000 $CONTROLS if active_year==1 | peacedurplus24!=., cl(dyad_id)

// Model 9: interaction
nbreg brv_All c.cfi_lag##c.troopLag1000 policeLag1000 milobsLag1000 $CONTROLS if sample == 1 , cl(dyad_id)


// Figure 5 UN and No UN : Model 8
nbreg brv_All c.cfi_lag##c.troopLag1000 policeLag1000 milobsLag1000 $CONTROLS if sample == 1 , cl(dyad_id)

set more off
margin, at(cfi_lag = (0 (0.1) 0.5) troopLag1000 = (0, 7) ) atmeans
# delimit ;
marginsplot, 
graphregion(color(white)) recast(line) recastci(rline) 
title("Data and Predicted Values (Model 8)") xtitle("CFI (t-1)") ytitle("Number of Battle Deaths")
plot2opts(lpattern("l") lcolor("dknavy") lwidth("thick"))
plot1opts(lpattern(shortdash) lcolor("cranberry") lwidth("medthick"))
ci2opts(lpattern("--") lcolor("dknavy")    lwidth("thin")  )
ci1opts(lpattern(shortdash) lcolor("cranberry") lwidth("thin") )
;

// Figure 4: Marginal Effects Model 8 spexcification dropping when brd is 0 & all data
nbreg brv_All c.cfi_lag##c.troopLag1000 policeLag1000 milobsLag1000 $CONTROLS , cl(dyad_id)

set more off
margin, dydx(cfi_lag) at(troopLag1000 = (0 (1) 29)) atmeans
# delimit ;
marginsplot, 
graphregion(color(white)) recast(line) recastci(rline)
plotopts(lpattern("l") lcolor("black") lwidth("thick") )
ciopts(lpattern("--") lcolor("black") lwidth("thin") )
title("Marginal Effect of CFI") xtitle("UN Troops (1000)") ytitle("Effect on Predicted Number of Battle Deaths")
;
